<script type="text/javascript" language="javascript" src="<?= base_url() ?>public/js/jquery.validate.js"></script>
<script src="<?php echo base_url(); ?>public/js/chosen.jquery.min.js" type="text/javascript"></script>
<script src="<?php echo base_url(); ?>public/js/date.js" type="text/javascript"></script>
<script src="<?php echo base_url(); ?>public/js/jquery.jqprint-0.3.js" type="text/javascript"></script>
<script>
    $(document).ready(function(){
        $('form[name=frm]').validate();
        var date = new Date();
        $(".iframe").colorbox({
            iframe:true, 
            width:"90%", 
            height:"90%"
        });
        $("#report-year").change(function(){
            if($(this).val()!=""){
                $('#report-fromdate').datepicker('setDate', new Date($(this).val(), 0 ,1));
                $('#report-todate').datepicker('setDate',  new Date($(this).val(), 11 ,31));
                reloadReport();                
            }
        }).chosen();         
        $("#report-fromdate").datepicker({
            onSelect: function(selected) {
                $( "#report-todate" ).datepicker("option", "minDate", selected);    
                 $("#report-year").val("").trigger("liszt:updated");
                reloadReport();
            }
        });
        $("#report-todate").datepicker({
            onSelect: function(selected) {
                $("#report-fromdate").datepicker("option", "maxDate", selected);
                 $("#report-year").val("").trigger("liszt:updated");
                reloadReport();
            }
        });
        var reloadReport = function(){
            $.ajax({
                url: "<?php echo base_url(); ?>index.php/admin/stock_issue",
                data : $("#report-filter-form").serialize(),
                type: "POST",
                dataType: "json",
                success: function(result){            
                    $.each(result, function(key, val) {
                        $("#medal-report-list td span[class='"+ val.Medal_Class_ID +"'][type='"+val.Medal_Type_ID+"']").html(Number(val.amount));
                    });
                }               
            });
            $.ajax({
                url: "<?php echo base_url(); ?>index.php/admin/get_issue_by_date",
                data : $("#report-filter-form").serialize(),
                type: "POST",
                dataType: "json",
                success: function(result){   
                    var id = "-";
                    $.each(result, function(key, val) {
                        id += val.ID+"-";
                    });
                    if(id.length > 2){              
                        var startDate = $("#report-fromdate").datepicker('getDate').toString("yyyy-MM-dd");  
                        var endDate = $("#report-todate").datepicker('getDate').toString("yyyy-MM-dd");  
                        var year = $("#report-year").val();  
                        $("#btnPrint").show();
                        id = id.substr(1, id.length-2);
                        $("#btnPrint").attr("href", "<?= site_url('/admin_stock/printSummary') ?>/"+startDate + "/" + endDate + "/" + year);    
                    }else{
                        $("#btnPrint").hide();                        
                    }
                }               
            });
        }
    });	
	
</script>

<div id="left-content">
    <div id="medal-report-panel" class="content-block">
        <div class="block-header">ចំនួនមេដាយដែលបានប្រគល់ជូនមន្ត្រីរាជការ  <div class="right"><a href="#" style="display: none;" class='iframe'  id="btnPrint">បោះពុម្ភ</a></div></div>
        <div id="block-content">
            <div id="search-panel">
                <fieldset>
                    <legend>ស្វែងរក</legend>
                    <form id="report-filter-form" name="report-filter-form" method="get">
                        <select id="report-year" name="report-year"/>
                        <option value="">ឆ្នាំ</option>
                        <option value="2010" >2010</option>
                        <option value="2011" >2011</option>
                        <option value="2012" >2012</option>
                        <option value="2013" >2013</option>
                        <option value="2014" >2014</option>
                        <option value="2015" >2015</option>
                        <option value="2016" >2016</option>
                        <option value="2017" >2017</option>
                        <option value="2018" >2018</option>
                        </select>
                        <input type="text" name="report-fromdate" id="report-fromdate" value="ពីថ្ងៃទី​" class="input text datepicker left populated-text" />
                        <input type="text" name="report-todate" id="report-todate" value="ដល់ថ្ងៃទី​"  class="input text datepicker left populated-text" />
                    </form>
                </fieldset>
            </div>
            <div id="medal-report-list">
                <div>
                    <table id="data-table" class="no-vertical-border medal-detail">
                        <tr>
                            <th scope="col">ប្រភេទ</th>
                            <th scope="col">មហាសិរីវឌ្ឍន៌</th>
                            <th scope="col">មហាសេនា</th>
                            <th scope="col">ធិបឌិន្ទុ</th>
                            <th scope="col">សេនា</th>
                            <th scope="col">អស្សរិទ្ធិ</th>
                        </tr>
                        <tr>
                            <th scope="row">ព្រះរាជាណាចក្រកម្ពុជា</th>
                            <td><span class="1" type="1"></span></td>
                            <td><span class="2" type="1"></span></td>
                            <td><span class="3" type="1"></span></td>
                            <td><span class="4" type="1"></span></td>
                            <td><span class="5" type="1"></span></td>
                        </tr>
                        <tr>
                            <th scope="row">សម្តេចព្រះមហាក្សត្រីយានី</th>
                            <td><span class="1" type="2"></span></td>
                            <td><span class="2" type="2"></span></td>
                            <td><span class="3" type="2"></span></td>
                            <td><span class="4" type="2"></span></td>
                            <td><span class="5" type="2"></span></td>
                        </tr>
                        <tr>
                            <th scope="row">សុវត្ថារា</th>
                            <td><span class="1" type="3"></span></td>
                            <td><span class="2" type="3"></span></td>
                            <td><span class="3" type="3"></span></td>
                            <td><span class="4" type="3"></span></td>
                            <td><span class="5" type="3"></span></td>
                        </tr>
                        <tr>
                            <th scope="row">មុនីសារ៉ាភ័ណ្ឌ</th>
                            <td><span class="1" type="4"></span></td>
                            <td><span class="2" type="4"></span></td>
                            <td><span class="3" type="4"></span></td>
                            <td><span class="4" type="4"></span></td>
                            <td><span class="5" type="4"></span></td>
                        </tr>
                        <tr>
                            <th scope="row">សហមេត្រី</th>
                            <td><span class="1" type="5"></span></td>
                            <td><span class="2" type="5"></span></td>
                            <td><span class="3" type="5"></span></td>
                            <td><span class="4" type="5"></span></td>
                            <td><span class="5" type="5"></span></td>
                        </tr>
                    </table>
                </div>
                <div>
                    <table id="data-table" class="no-vertical-border">
                        <tr>
                            <th scope="col">ប្រភេទ</th>
                            <th scope="col">មាស</th>
                            <th scope="col">ប្រាក់</th>
                            <th scope="col">សំរឹទ្ធ</th>
                        </tr>
                        <tr>
                            <th scope="row">ការពារជាតិ</th>
                            <td><span class="6" type="6"></span></td>
                            <td><span class="7" type="6"></span></td>
                            <td><span class="8" type="6"></span></td>
                        </tr>
                        <tr>
                            <th scope="row">ការងារ</th>
                            <td><span class="6" type="7"></span></td>
                            <td><span class="7" type="7"></span></td>
                            <td><span class="8" type="7"></span></td>
                        </tr>
                        <tr>
                            <th scope="row">ស្ថាបនាជាតិ</th>
                            <td><span class="6" type="8"></span></td>
                            <td><span class="7" type="8"></span></td>
                            <td><span class="8" type="8"></span></td>
                        </tr>
                        <tr>
                            <th scope="row">ស្ត្រីវឌ្ឍនា</th>
                            <td><span class="6" type="9"></span></td>
                            <td><span class="7" type="9"></span></td>
                            <td><span class="8" type="9"></span></td>
                        </tr>
                        <tr>
                            <th scope="row">ខេមរាកីឡារិទ្ធិ</th>
                            <td><span class="6" type="10"></span></td>
                            <td><span class="7" type="10"></span></td>
                            <td><span class="8" type="10"></span></td>
                        </tr>
                    </table>
                </div>
                <div>
                    <table id="data-table" class="no-vertical-border">
                        <tr>
                            <th scope="col">ប្រភេទ</th>
                            <th scope="col">&nbsp;</th>
                        </tr>
                        <tr>
                            <th scope="row">ជាតូបការ</th>
                            <td><span class="null" type="11"></span></td>
                        </tr>
                        <tr>
                            <th scope="row">ឯករាជ្យជាតិ</th>
                            <td><span class="null" type="12"></span></td>
                        </tr>
                        <tr>
                            <th scope="row">សេនាជ័យសិទ្ធ</th>
                            <td><span class="null" type="13"></span></td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--<div id="related-activity" class="content-block right">
  <div class="block-header">ប្រតិបត្តិសំខាន់ៗ</div>
  <div id="block-content"></div>
</div>-->
